from sympy import Rational,Integer,sympify,symbols
import sympy as sym
import fractions
from decimal import Decimal
import decimal
import math


def isSymType(symObj, type):
    # 将输入的 type 字符串转换成 SymPy 可识别的表达式对象
    type_expr = str(sympify(type))
    flag = isinstance(symObj,Rational)
    flag2 = type_expr == 'rational'
    # 如果 symObj 本身就是 type 类型，返回 True
    if (isinstance(symObj,Integer) or isinstance(symObj,int)) and type_expr == 'integer' :
        return True
    elif isinstance(symObj,Rational) and type_expr == 'rational':
        return True
    elif isinstance(symObj,Decimal) and type_expr == 'vpareal':
        return True
    elif isinstance(symObj,complex) and type_expr == 'complex':
        return True
    elif ((isinstance(symObj,Integer) or isinstance(symObj,int))
          or isinstance(symObj,Rational) 
          or isinstance(symObj,Decimal)
          or isinstance(symObj,fractions.Fraction)) and (type_expr == 'real' or type_expr == 'number'):
        return True
    
    # 对于其他情况，返回 False
    else:
        return False




# 定义一些 SymPy 符号
x, y, z = symbols('x y z')
rational_num = sym.Rational(1,2)
vpareal_num = decimal.Decimal('3.14')
complex_num = complex(1,2)
real_num = fractions.Fraction(1,2)
irrational_num = math.sqrt(2)
num = sym.numer(1)
num2 = 1
# 测试 isSymType 函数

print(isSymType(sympify(1), 'integer'))     # 输出结果为 True
print(isSymType(rational_num,'rational'))   # 输出结果为 True
print(isSymType(vpareal_num,'vpareal'))     # 输出结果为 True
print(isSymType(complex_num,'complex'))     # 输出结果为 True
print(isSymType(real_num,'real'))           # 输出结果为 True
print(isSymType(rational_num,'real'))       # 输出结果为 True
print(isSymType(num2,'number'))             # 输出结果为 True

print(isSymType(rational_num,'vpareal'))    # 输出结果为 False
print(isSymType(irrational_num,'real'))     # 输出结果为 False
